<?php

namespace models;

class User {
		
	/** 根据openid获取用户 **/
	public static function getByOpenid($db, $openid) {
        $sql = "SELECT * FROM t_user WHERE isDeleted = 0 AND openid =?";
	    $data = $db->fetchAssoc($sql, array($openid));
	    return $data;
    }

    /** 注册 **/
	public static function add($db, $openid, $name, $avatar) {
        $sql = "INSERT INTO t_user(openid, nickName, avatar, createdAt, modifiedAt, isDeleted) VALUES(?,?,?,?,?,?)";
	    $data = $db->executeUpdate($sql, array($openid, $name, $avatar, time(), time(), false));
	    return $db->lastInsertId();
    }
}